node('slave') {
	stage('同步源码') {
		git([url: 'git@gitee.com:yivqin/newbell_mall.git', branch: '$branch'])
	}
	stage('编译打包') {
		sh '''
			. /etc/profile
			cd newbee-mall-api-master
			mvn clean install -Dmaven.test.skip=true
			mvn clean package spring-boot:repackage -Dmaven.test.skip=true -U 
		'''
	}
	stage('停止tomcat') {
		sh '''
			tomcatkill(){
				pid=`ps -ef|grep $1|grep java|awk '{print $2}'`
				if [ "${pid}" != "" ]
				then
					kill -9 $pid
				else
					echo 'tomcat is not in process'
				fi
			}
			tomcatkill $tomcat_home
		'''
	}
	stage('清理环境') {
		sh '''
			rm -f $tomcat_home/webapps/mall.war
			rm -rf $tomcat_home/webapps/RUN
		'''
	}
	stage('部署新包') {
		sh '''
			export pwd=`pwd`
			cp $pwd/newbee-mall-api-master/target/newbee-mall-api-3.0.0-SNAPSHOT.jar $tomcat_home/webapps/
			cd $tomcat_home/webapps
			mv newbee-mall-api-3.0.0-SNAPSHOT.jar newbee-mall.jar
		'''
	}
	stage('重启tomcat') {
		sh '''
			JENKINS_NODE_COOKIE=dontkillme
			cd $tomcat_home/bin
			bash startup.sh
		'''
	}
}